package gao.xiaolei;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableEurekaClient
@RestController
public class BusApplication {

    public static String defaultPort = "9000";// 默认端口号

    @Autowired
    private Environment env;

    @RequestMapping("/testConfigFile")
    public String home() {
        return "Hello" + env.getProperty("name");
    }

    public static void main(String[] args) {
        // 由于编译器的版本不同所以需要判断是不是最前面会默认有一个
        int i = 0;
        if (args.length == 2)
            i = 1;
        if (!"0".equals(args[i]))// 输入0表示端口号使用默认端口号,反之则不是
            defaultPort = args[i];
        new SpringApplicationBuilder(BusApplication.class).properties(
                "server.port=" + defaultPort).run(args);
    }
}
